import Taro, { Component } from '@tarojs/taro'
import { Swiper, SwiperItem, Image, View, Text,RichText} from '@tarojs/components'
import '../../assets/common.scss'
import CommonJs from '../../utils/common'
import '../news/newlist.scss'




export default class Index extends Component {
  constructor(props) {
    super(props);
    this.state = {
        newslist:[],
        content:'',
        isshow:0
    }
  }
  config = {
    navigationBarTitleText: '加载中'
  }
  componentWillMount () {
    var type = this.$router.params.type;
    this.getnewtitle(type);
    this.ydl(type);
    this.getmb(type)
  }
  ydl(type){
  	var url = '/advert/papi/v1.9/news/reading/quantity?newsId='+type
  	CommonJs.ajaxRequest(url, '', 'POST', function(res) {})
  }
  getnewtitle(type) {
	// var url = '/advert/papi/v1.9/notice/obtain/' + shopid
	var url = '/advert/papi/v1.9/news/get/'+type
    var _this = this
    CommonJs.ajaxRequest(url, '', 'GET', function(res) {
    var str=res.data.content;
    Taro.setNavigationBarTitle({title:res.data.title})
    var pstr=str.replace(/uni-view/g,'div')
    var ppstr = pstr.replace(/<img/g,'<img class="new-imgs"')
      _this.setState({
        newslist: res.data,
        content:ppstr,
        isshow:1
      })
    },'wfw')
  }
  getmb(type){
  	var url='/advert/papi/v1.9/news-target/byNews/'+type
  	CommonJs.ajaxRequest(url, '', 'POST', function(res) {})
  }
  onShareAppMessage(res){
    let title =this.state.newslist.title
    let path='/pages/news/newtitle?type='+this.state.newslist.id
    let imageUrl = this.state.newslist.titlePic
    return CommonJs.onShareAppMessage(title, path, imageUrl)
  }
  render () {
      const newlist = this.state.newslist
    return (
      <View className='page' style={this.state.isshow==1?'':'display:none'}>
        <View className='new-list'>
            <View className='new-top'>{newlist.title}</View>
            <View className='new-time'>
            	<Button openType='share' style="float:right;margin-right:3%;background:none;padding:0;line-height:30rpx;">
	              <Image style="width:30rpx;height:30rpx" mode='scaleToFill' src='https://minichat.g2ma.com/kedouimg/40.png'></Image>
	            </Button>
            	{CommonJs.FormatDate(newlist.createAt,3)}
            	<Text style="padding-left:50px;">阅读量：{newlist.readingQuantity}</Text>
            	
            </View>
            <View className='new-li'>
            <RichText  className='new-li' nodes={this.state.content} />
            </View>
           
        </View>
      </View>
    )
  }
}